﻿#include "screen_lock.h"
#include <windows.h>

namespace screenlock
{
    enum MONITOR_POWER_LPARAM
    {
        SCREEN_ON = -1, // -1 (显示器打开)
        SCREEN_POWER_SAVE = 1, // 1 (显示器将进入低功耗)
        SCREEN_OFF = 2 // 2 (显示器关闭)
    };

    // 锁定计算机
    void lock_computer()
    {
        // 调用 Windows API 锁定计算机
        LockWorkStation();
    }

    // 关闭屏幕
    void turn_off_screen()
    {
        const auto hWnd = HWND_BROADCAST;
        constexpr UINT uMsg = WM_SYSCOMMAND;
        constexpr WPARAM wParam = SC_MONITORPOWER;
        constexpr LPARAM lParam = SCREEN_OFF;
        // 发送消息关闭屏幕
        SendMessage(hWnd, uMsg, wParam, lParam);
    }
}
